import { ref, watch } from 'vue';

// 自定义HOOK，响应式操作
export default function (uid) {
    let isVip = ref(0);
    let vipStatusMap = {};
    isVip.value = 0; // 请求中
    watch([uid], (newUid) => {
        if(vipStatusMap[newUid]){
            isVip.value = vipStatusMap[newUid];
        }else{
            isVip.value = 0;
            setTimeout(() => {
                var fetchRes = Math.random() > 0.5;
                isVip.value = fetchRes ? 1 : 2; 
                vipStatusMap[newUid] = isVip.value;
            }, 1000);
        }
    }, {
        immediate: true, // 初始化的时候也触发一次
    });
    return isVip;
}